﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BizControl.Library.BusinessObjects.People;
using BizControl.Library.BusinessObjects.Models;

namespace BizControl.Library.Tests
{
  [TestClass]
  public class ModelBOFixture
  {
    private PersonBO NewPerson()
    {
      var person = PersonBO.NewPerson();
      person.FirstName = "Michael";
      person.LastName = "Baranov";
      person.PasswordHash = "passwordHash";
      person.PasswordSalt = "passwordSalt";
      person.Login = "michael.baranov";
      person.Email = "bla@bla.bla";
      return person;
    }

    [TestMethod]
    public void AddModelBOTest()
    {
      // login
      var model = ModelBO.NewModel();
      model.Name = "Model #1";
      model = model.Save();
      var model2 = ModelBO.GetModel(model.ModelId);
      Assert.AreEqual(model.ModelId, model2.ModelId);
    }

    [TestMethod]
    public void AddPersonToNewModelTest()
    {
      // login
      var model = ModelBO.NewModel();
      model.Name = "Model #2";
      var person = NewPerson();
      person = person.Save();
      model.People.AddPerson(person);
      model = model.Save();
      Assert.IsTrue(ModelBO.GetModel(model.ModelId).People.Contains(person.PersonId));
    }

    [TestMethod]
    public void AddPersonToModelTest()
    {
      // login
      var modelInfo = ModelList.GetModelList().FirstOrDefault();
      var model = ModelBO.GetModel(modelInfo.Id);
      var personInfo = PersonList.GetPersonList().FirstOrDefault();
      var person = PersonBO.GetPerson(personInfo.Id);
      model.People.AddPerson(person);
      model = model.Save();
      Assert.IsTrue(ModelBO.GetModel(model.ModelId).People.Contains(personInfo.Id));
    }

    [TestMethod]
    public void AddModelToPersonTest()
    {
      // login
      var personInfo = PersonList.GetPersonList().FirstOrDefault();
      var person = PersonBO.GetPerson(personInfo.Id);
      var model = ModelBO.NewModel();
      model.Name = "Model #Y Hello, World!!! This is a new company";
      model = model.Save();
      person.Models.AddModel(model);
      person.Save();
      Assert.IsTrue(ModelBO.GetModel(model.ModelId).People.Contains(person.PersonId));
    }

  }
}
